//
//  SmallScrollView.m
//  UI_06作业滚动视图
//
//  Created by dllo on 16/6/13.
//  Copyright © 2016年 dllo. All rights reserved.
//
#define ScreeenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#import "SmallScrollView.h"

@implementation SmallScrollView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createScrollView];
    }
    return self;
}
- (void)createScrollView{
    self.pagingEnabled = YES;
    
    self.bounces = NO;
    
   }
- (void)addPicture:(NSArray *)pictureArray{
    for (NSInteger i = 0; i < pictureArray.count; i++) {
        UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(ScreeenWidth * (i + 1), 0, ScreeenWidth, ScreenHeight)];
        scroll.delegate = self;
        //放大缩小
        scroll.minimumZoomScale = 0.5;
        scroll.maximumZoomScale = 2;

        [self addSubview:scroll];
        //确定滚动范围
        self.contentSize = CGSizeMake(CGRectGetWidth(self.bounds) * pictureArray.count, CGRectGetHeight(self.bounds));
 
        UIImageView *imageView = [[UIImageView alloc] initWithImage:pictureArray[i]];
        imageView.frame = CGRectMake(i * CGRectGetWidth(self.bounds), 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds));
        imageView.userInteractionEnabled = YES;
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapImageView:)];
//        [imageView addGestureRecognizer:tap];
        [scroll addSubview:imageView];
        [imageView release];
    }
}
#pragma mark -- 缩放的代理方法
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return scrollView.subviews.firstObject;
}

@end
